/**
  ******************************************************************************
  * @file    lcd.h
  * @brief   This file contains all the function prototypes for
  *          the lcd.c file
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 微信公众号：物联网客栈.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

#ifndef __DEVICE_H__
#define __DEVICE_H__

#include "main.h"
#include <stdint.h>

#define kNoErr               0
#define kGeneralError        -1

// 设备ID枚举
typedef enum {
    DEVICE_ID_WIFI = 0,         // WIFI模块
    DEVICE_ID_LCD,              // LCD显示屏
	DEVICE_ID_TEMP,             // 温湿度传感器
    DEVICE_ID_PM25,             // PM2.5传感器
    DEVICE_ID_NOISE,            // 噪声传感器
    DEVICE_ID_MAX               // 设备数量上限
} E_DeviceID_t;

// 设备操作接口
typedef struct {
    int (*init)(void* priv);
    int (*read)(void* priv, void* buffer, uint32_t size);
    int (*write)(void* priv, const void* buffer, uint32_t size);
    int (*control)(void* priv, int cmd, void* arg);
} DeviceOps_t;

// 设备结构体
typedef struct {
    E_DeviceID_t id;            // 设备ID
    const DeviceOps_t* ops;   // 设备操作接口
    void* priv;             // 设备私有数据
} DeviceCTX_t;

// 注册设备
int device_register(DeviceCTX_t* dev);

// 查找设备
DeviceCTX_t* device_find(E_DeviceID_t id);

// 初始化设备
int device_init(E_DeviceID_t id);

// 读取设备数据
int device_read(E_DeviceID_t id, void* buffer, uint32_t size);

// 写入设备数据
int device_write(E_DeviceID_t id, const void* buffer, uint32_t size);

// 控制设备
int device_control(E_DeviceID_t id, int cmd, void* arg);


#endif

